#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "qipan.h"
#include <QMainWindow>
#include <QPushButton>
#include <QLabel>
#include <QComboBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "motorcontroller.h"
#include "chessdetectionwindow.h"
#include "servocontroller.h"
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    
    QPoint convertBoardCoordToMotor(int boardX, int boardY);

private slots:
    void updateGameStatus();
    void onResetClicked();
    void onPlayerRoleChanged(int index);
    void onAIDifficultyChanged(int index);
    void onPlayerMoved(int x, int y);
    void onComputerMoved(int x, int y);
    void onOpenDetectionWindow();
    void handleDetectionInfo(const QString &info);
    void handleVerificationResult(int boardX, int boardY, bool success);
    void handlePieceLocked(const std::string& pieceName, int motorX, int motorY);
    void handleServoCommand(quint8 state, quint8 row, quint8 col);
    void handlePiecesRemoved(const QList<QPair<ROLE, QPoint>>& pieces);
    void movePieceToTarget(const QPoint& from, const QPoint& to, bool isBlack);

private:
    QiPan *qipan;
    QLabel *statusLabel;
    QPushButton *resetButton;
    QPushButton *regretButton;
    QComboBox *playerRoleCombo;
    QComboBox *aiDifficultyCombo;
    MotorController *motorController;
    ServoController *servoController;
    QPushButton *detectionButton;
    ChessDetectionWindow *detectionWindow;
    ChessDetector *chessDetector;
    QList<QPair<QPoint, QPoint>> moveQueue; 
    bool isMoving = false;                 
    void processNextMove();                
    
};

#endif // MAINWINDOW_H
